package com.by.group;

import com.by.ex.ValidateException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * date 2025/2/14 19:10
 * author bjj
 * decoration
 * version 1.0
 * since jdk11
 */
public class V {
    public static  void validate(BindingResult result){
        List<FieldError> errors = result.getFieldErrors();
        if(!errors.isEmpty()){
            Map<String,String> errorMap = new HashMap<>();
            errors.forEach(el->{
                errorMap.put(el.getField(),el.getDefaultMessage());
            });
            throw new ValidateException(errorMap);
        }
    }
}
